home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CAS_HelpBalloon.c
-
- Contains: balloon help code.
-
- Written by: David H Nelson
-
- Copyright © 1993-1995 ComponentWorks, All rights reserved.
-
- Change History (most recent first):
-
- <2> 9/13/95 TWB Comment out unnecessary include of CALib.
- <1> 11/20/93 DHN Created.
- */
-
- #include <Balloons.h>
- #include "CAS_HelpBalloon.h"
- #include "CAS_Globals.h"
- #include "CAS_Doc.h"
-
- //----------------------------------------------------------------------
-
- RgnHandle hotRgn = nil;
-
- //----------------------------------------------------------------------
-
- void hideBalloons( WindowPtr theWindow )
- {
- // if balloon help is not on, get out.
- if (!HMGetBalloons())
- return;
-
- // if the hotRgn hasn't been allocated, create it.
- if (!hotRgn)
- hotRgn = NewRgn();
-
- // if our existing balloon hotRgn is not empty…
- if (!EmptyRgn(hotRgn))
- {
- // if there is a balloon showing, hide it.
- if (HMIsBalloon())
- HMRemoveBalloon(); // hide the balloon.
-
- SetRectRgn(hotRgn,0,0,0,0); // clear the hotRgn
- }
- }
-
- //----------------------------------------------------------------------
-
- void doBalloonHelp( WindowPtr theWindow )
- {
- short index;
- Rect hotRect;
- Rect growRect;
- Point aPoint;
- HMMessageRecord helpMsg;
- HMStringResType *hmString;
- OSErr theErr;
- DocPtr theDoc;
-
- // if balloon help is not on, get out.
- if (!HMGetBalloons())
- return;
-
- // if the hotRgn hasn't been allocated, create it.
- if (!hotRgn)
- hotRgn = NewRgn();
-
- // if there's no window don't do anything
- if (!theWindow)
- return;
-
- // if the window is not hilited, our GetMouse will return the global mouse position
- // which will screw up the rest of our code below, so don't do anything.
- if (!((WindowPeek) theWindow)->hilited)
- return;
-
- theDoc = (DocPtr) GetWRefCon(theWindow);
-
- GetMouse( &aPoint );
-
- // if our existing balloon hotRgn is not empty…
- if (!EmptyRgn(hotRgn))
- {
- // if we're still in the hotRgn, get out.
- if (PtInRgn( aPoint, hotRgn ))
- return;
-
- // we're not in the hotRgn, so
- // if there is a balloon showing, hide it, clear the hotRgn, and get out.
- if (HMIsBalloon())
- {
- HMRemoveBalloon(); // hide the balloon.
- SetRectRgn(hotRgn,0,0,0,0); // clear the hotRgn
- return;
- }
- }
-
- growRect = theWindow->portRect;
- growRect.left = growRect.right - SBARWIDTH + 1;
- growRect.top = growRect.bottom - SBARWIDTH + 1;
-
- if (PtInRect( aPoint, &theDoc->hScrollBarRect ))
- {
- index = 1;
- RectRgn(hotRgn, &theDoc->hScrollBarRect);
- }
- else if (PtInRect( aPoint, &theDoc->vScrollBarRect ))
- {
- index = 2;
- RectRgn(hotRgn, &theDoc->vScrollBarRect);
- }
- else if (PtInRect( aPoint, &growRect))
- {
- index = 3;
- RectRgn(hotRgn, &growRect);
- }
- else if (PtInRect( aPoint, &theDoc->contentRect ))
- {
- index = 4;
- RectRgn(hotRgn, &theDoc->contentRect);
- }
- else
- {
- SetRectRgn(hotRgn,0,0,0,0); // clear the hotRgn
- return;
- }
-
- /******************************************************************/
- /* Grab the string from the 'STR#' resource for the help message. */
- /******************************************************************/
-
- hotRect = (**hotRgn).rgnBBox;
-
- LocalToGlobal( &topLeft( hotRect ) );
- LocalToGlobal( &botRight( hotRect ) );
-
- // SetPt( &aPoint, ((hotRect.right - hotRect.left) >> 1) + hotRect.left,
- // ((hotRect.bottom - hotRect.top) >> 1) + hotRect.top );
- LocalToGlobal( &aPoint );
-
- helpMsg.hmmHelpType = khmmStringRes;
-
- hmString = (HMStringResType*)&helpMsg.u;
-
- (*hmString).hmmResID = kMainWindowHelpStrings;
- (*hmString).hmmIndex = index;
-
- theErr = HMShowBalloon( &helpMsg, aPoint, &hotRect, nil, 0, 0, kHMSaveBitsWindow );
-
- // if there were any errors (like the cursor constantly moving) start over.
- if (theErr != noErr)
- SetRectRgn(hotRgn,0,0,0,0);
- }
-
-